package com.bw.zg3park2212.fangke

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.bw.base.entity.FangAddParam
import com.bw.base.mvvm.BaseActivity
import com.bw.zg3park2212.R
import com.bw.zg3park2212.databinding.ActivityFangAddBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path="/app/FangAddActivity")
class FangAddActivity : BaseActivity<ActivityFangAddBinding,FangViewModel>() {
    override fun intitView() {
        binding.visitaddIvstart.setOnClickListener {
            showTime(binding.visitaddStart)
        }
        binding.visitaddIvend.setOnClickListener {
            showTime(binding.visitaddEnd)
        }
        binding.visitaddIvdate.setOnClickListener {
            showDate(binding.visitaddDate)
        }
        //点击按钮
        binding.visitaddSwitch.setOnCheckedChangeListener { buttonView, isChecked ->
            binding.visitaddCarNo.isEnabled=isChecked
        }
        binding.add.setOnClickListener {
            var fangAddParam=FangAddParam()
            fangAddParam.visitorName=binding.visitaddUser.text.toString()
            fangAddParam.phoneNumber=binding.visitaddPhone.text.toString().toLong()
            fangAddParam.appointmentTime=binding.visitaddDate.text.toString()+" "+binding.visitaddStart.text.toString()
            fangAddParam.idNumber=binding.visitaddCard.text.toString().toLong()
            fangAddParam.purpose=binding.visitaddPurpose.text.toString()
            fangAddParam.plateNumber=binding.visitaddCarNo.text.toString()
            fangAddParam.employeeId=binding.visitaddEmp.text.toString().toInt()
            viewmodel.getfangAdd(fangAddParam)
        }
    }

    override fun intitData() {
        viewmodel.fangAddSuccse.observe(this){
            ToastUtils.showLong("添加成功")
            finish()
        }
    }

}